<?php

namespace IDock\Insurance\ZYIC\Request;

use GuzzleHttp\Psr7\Stream;
use IDock\Http\RequestFormat;
use IDock\IDock\IDockEnums;
use IDock\Insurance\ZYIC\Request\AllZYICRequest;
use IDock\Insurance\ZYIC\Response\UploadFileResponse;
use IDock\Insurance\ZYIC\ZYICEnums;
use IDock\Visitor\Premium\PremiumInquiryVisitor;
use IDock\Visitor\UploadFileVisitor;

class UploadFileRequest extends AllZYICRequest
{
    public $route = 'channelInterface/V32';

    protected $response = UploadFileResponse::class;

    protected $urlTip = '影像上传';

    protected $inLog = true;

    /**
     * @var  UploadFileVisitor $visitor
     */
    protected $visitor;

    public function generate(): array
    {
       $arr = [
           'proposalNo' => ($this->visitor->argc['proposalNoBI'] ?? '') ?: ($this->visitor->argc['proposalNoCI'] ?? ''),
           'imageBaseDataList' => $this->getImageList()
       ];
        return $arr;
    }

    private function getImageList()
    {
        $list = [];
        foreach ($this->visitor->getFileList() as $value){
            $list[] = [
                'imageType' => ZYICEnums::$uploadFileType[$value['type']],
                'picture' => [base64_encode(file_get_contents($value['url']))]
            ];
        }
        return $list;
    }

}
